<template>
	<view class="container">
		<!-- 头部导航 -->
		<page-navbar title="景区美食" backgroundColor="#87CEEB00" color="#fff" leftIconColor="#fff"></page-navbar>

		<!-- 主要内容区域 -->
		<scroll-view class="content" scroll-y="true" :show-scrollbar="false">
			<!-- 搜索栏 -->
			<view class="search-section">
				<view class="search-box">
					<svg-icon name="search" size="32" />
					<input class="search-input" placeholder="搜索美食" />
				</view>
			</view>

			<!-- 美食列表 -->
			<view class="section">
				<view class="section-header">
					<view class="section-decoration">
						<svg-icon name="restaurant" size="32" />
					</view>
					<text class="section-title">景区美食介绍</text>
				</view>
				<view class="food-list" v-if="foodList.length > 0">
					<view class="food-item" v-for="(item, index) in foodList" :key="index"
						@click="handleFoodClick(item)">
						<image class="food-image" :src="common.defaultImg(item.coverId)" mode="aspectFill"></image>
						<view class="food-content">
							<view class="food-name">{{ item.name }}</view>
							<view class="food-desc">{{ item.introTitle }}</view>
							<view class="food-location" v-if="item.position">
								<view class="location-icon">
									<svg-icon name="location" size="20" />
								</view>
								<text class="location-text">{{ item.position?.name }}</text>
							</view>
						</view>
						<uni-icons type="right" color="#4CAF50" size="20"></uni-icons>
					</view>
				</view>
				<default-page v-else title="暂无美食信息" tip="精美美食正在准备中，敬请期待..."></default-page>
			</view>

			<!-- 底部占位 -->
			<view class="bottom-placeholder"></view>
		</scroll-view>
	</view>
</template>

<script setup>
import { ref, reactive, onMounted, watch, computed, nextTick, toRefs } from 'vue';
import { onLoad, onShow, onShareAppMessage } from '@dcloudio/uni-app';
import common from '@/utils/common.js';
import api from '@/api/index.js';

import useUserInfoStore from '@/stores/user';
import { storeToRefs } from 'pinia';
import SvgIcon from '@/components/svg-icon/svg-icon.vue'

const userInfoStore = useUserInfoStore();
const { userData } = toRefs(userInfoStore);

const imgUrl = uni.imgUrl;

// 美食介绍数据
const foodList = ref([]);

onLoad(() => { });

onMounted(() => {
	getList();
});

const getList = () => {
	api.attractionsApi.listSpots({ typeId: 9 }).then((res) => {
		console.log('美食列表', res);
		foodList.value = res
	}).catch((error) => {
		console.error('获取美食列表失败:', error);
	});
};

// 点击美食
const handleFoodClick = (item) => {
	// 跳转到美食详情页
	uni.navigateTo({
		url: `/pages/details/foodDetail?id=${item.id}`
	});
};
</script>

<style lang="scss" scoped>
.container {
	background: linear-gradient(180deg, #c887eb 0%, #fbf0ff 50%, #ffffff 100%);
	height: 100vh;
	width: 100%;
	position: relative;
	overflow: hidden;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
}

.content {
	flex: 1;
	overflow: hidden;
	box-sizing: border-box;
	position: relative;
	z-index: 1;
	padding: 0 30rpx 24rpx;

	.search-section {
		padding: 0 0 30rpx 0;

		.search-box {
			display: flex;
			align-items: center;
			gap: 24rpx;
			background: rgba(255, 255, 255, 0.9);
			border-radius: 50rpx;
			padding: 20rpx 30rpx;
			box-shadow: 0 4rpx 20rpx rgba(135, 206, 235, 0.15);


			.search-input {
				flex: 1;
				font-size: 28rpx;
				color: #333;

				&::placeholder {
					color: #999;
				}
			}
		}
	}
}

.section {
	margin-bottom: 40rpx;

	.section-header {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
		padding: 0 10rpx;
		gap: 20rpx;

		.section-title {
			font-size: 32rpx;
			font-weight: bold;
			color: #2E7D32;
		}

		.section-decoration {
			width: 32rpx;
			height: 32rpx;
			opacity: 0.7;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
}

/* 美食介绍列表 */
.food-list {
	.food-item {
		background: rgba(255, 255, 255, 0.95);
		border-radius: 20rpx;
		padding: 25rpx;
		margin-bottom: 20rpx;
		display: flex;
		align-items: flex-start;
		box-shadow: 0 4rpx 20rpx rgba(135, 206, 235, 0.1);
		transition: all 0.3s ease;

		&:active {
			transform: scale(0.98);
		}

		.food-image {
			width: 160rpx;
			height: 120rpx;
			border-radius: 12rpx;
			margin-right: 20rpx;
			flex-shrink: 0;
		}

		.food-content {
			flex: 1;
			min-height: 120rpx;
			display: flex;
			flex-direction: column;

			.food-name {
				font-size: 30rpx;
				font-weight: bold;
				color: #2E7D32;
				margin-bottom: 8rpx;
			}

			.food-desc {
				font-size: 24rpx;
				color: #666;
				line-height: 1.5;
				margin-bottom: 12rpx;
				flex: 1;
				/* 限制显示3行，超出显示省略号 */
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.food-location {
				display: flex;
				align-items: center;
				gap: 6rpx;

				.location-icon {
					width: 20rpx;
					height: 20rpx;
					opacity: 0.7;
					display: flex;
					align-items: center;
					justify-content: center;
				}

				.location-text {
					font-size: 22rpx;
					color: #4CAF50;
					font-weight: 500;
				}
			}
		}

		.uni-icons {
			margin-top: 50rpx;
			flex-shrink: 0;
		}
	}
}

.bottom-placeholder {
	height: 100rpx;
}
</style>
